﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using Itop.YHPC.Model;
using System.Collections.Generic;
using Itop.YHPC.controller;

namespace Itop.YHPC.reward
{
    public partial class search_ajax : AjaxPage<yhpcMain>
    {
        protected override IList<yhpcMain> onRead()
        {
            string fxrq1 = Request.QueryString["fxrq1"];
            string check = Request.QueryString["check"];
            int page = int.Parse(Request.QueryString["page"]);
            int limit = int.Parse(Request.QueryString["limit"]);
            IList<yhpcMain> list = new List<yhpcMain>();
            if (fxrq1 != "100") {
                string yhjt = Request.QueryString["yhjt"];
                string zt = Request.QueryString["zt"];
                string pgdj = Request.QueryString["pgdj"];
                string fxrq2 = Request.QueryString["fxrq2"];
                string yhszdw = Request.QueryString["yhszdw"];
                string yhbh = Request.QueryString["yhbh"];
                string yhly = Request.QueryString["yhly"];
                string gsbm = Request.QueryString["gsbm"];
                string sfxc = Request.QueryString["sfxc"];
                string yhzyfl = Request.QueryString["yhzyfl"];
                string ypgdj = Request.QueryString["ypgdj"];
                StringBuilder sbulder = new StringBuilder();
                sbulder.Append(" where 1=1 ");
                if (zt != "" && zt != "全部")
                    sbulder.Append(" and lcstatus='" + zt + "'");
                if (ypgdj != "" && ypgdj != "全部")
                    sbulder.Append(" and ypgdj='" + ypgdj + "'");
                if (pgdj != "" && pgdj != "全部")
                    sbulder.Append(" and pgdj='" + pgdj + "'");
                if (fxrq1 != "") {
                    if (check == "true")
                        sbulder.Append(" and ysrq>='" + fxrq1 + "'");
                    else
                        sbulder.Append(" and fxrq>='" + fxrq1 + "'");
                }
                if (fxrq2 != "") {
                    if (check == "true")
                        sbulder.Append(" and ysrq<='" + fxrq2 + "'");
                    else
                        sbulder.Append(" and fxrq<='" + fxrq2 + "'");
                }
                if (yhly != "" && yhly != "全部")
                    sbulder.Append(" and yhly='" + yhly + "'");
                if (gsbm != "" && gsbm != "全部")
                    sbulder.Append(" and gsbm='" + gsbm + "'");
                if (yhzyfl != "" && yhzyfl != "全部")
                    sbulder.Append(" and yhzyfl='" + yhzyfl + "'");
                if (sfxc != "" && sfxc != "全部")
                    sbulder.Append(" and yssfxc='" + sfxc + "'");
                if (yhjt != "")
                    sbulder.Append(" and yhjt like '%" + yhjt + "%'");
                if (yhszdw != "")
                    sbulder.Append(" and yhdw like '%" + yhszdw + "%'");
                if (yhbh != "")
                    sbulder.Append(" and yhbh like '%" + yhbh + "%'");
                if (check == "true") {                    
                    sbulder.Append(" and datediff(day,zlrq2,ysrq)>3");
                }
                sbulder.Append(" order by fxrq desc");
                list = workflowController.GetMainList(sbulder.ToString());

            }
            total = list.Count;
            return GetPageList(page, list, limit);
        }
        protected override bool onUpdate(IList<yhpcMain> list) {
            
            foreach (yhpcMain obj in list) {

                workflowController.Update(obj);
            }
            return true;
        }
        int total = 0;
        protected override int GetTotal() {
            return total;
        }

        public IList<yhpcMain> GetPageList(int page, IList<yhpcMain> list, int limit) {
            IList<yhpcMain> temp = new List<yhpcMain>();
            for (int i = (page - 1) * limit; i < ((page * limit) > list.Count ? list.Count : (page * limit)); i++) {
                temp.Add(list[i]);
            }
            return temp;
        }
    }
}
